/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.actions;

import EDT.form.ModifierCrForm;
import EDT.obj.Calendrier;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author ali
 */
public class ModifierCrAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        
         ModifierCrForm f = (ModifierCrForm) form;
        
       String m="";
        
       if (f.getOptions().length <=0) m= "Vous n'avez pas séléctioner des créneaux à modifier ";
       
       else m = EDT.api.API.modifierCreneau(f.getKey(),f.getOptions(),
               f.getTypeModif(),f.getSalle(),f.getInterv(),f.getVisib(),
               f.getHdebut(),f.getHfin(),f.getDuree(),f.getJour(),
               f.getTimeDecal(),f.getDecalage());
        
       //m= f.toString();
        
       
        int annee = EDT.api.API.getAnnee(f.getPromo());
        Calendrier c = EDT.api.API.getAllCalendrierPromo(f.getKey(),f.getPromo(), f.getPeriode(),f.getNbrPeriode(),f.getGrp());
        c.setTitre("Emplois du temps " +" "+f.getFormation()+"<br/>Promotion : "+annee+"/"+(annee+1)+"<br/>Groupe : "+f.getGrp());
        request.setAttribute("calendrier", c.perideToTableHTMLClick("modification"));
        
        request.setAttribute("annee", annee);
        
        
        request.setAttribute("formation",f.getFormation());
        request.setAttribute("promo", f.getPromo());
        request.setAttribute("periode", f.getPeriode());
        request.setAttribute("nbrPeriode", f.getNbrPeriode());
        request.setAttribute("grp", f.getGrp());
       
       
       if(m.equals("")){
         
           m += "<label style='color:#009F3C;'>"
                   +f.getOptions().length
                   +" créneau(x) a(ont) été modifié(s) ! </label>";
           

       }
          

       request.setAttribute("msg", "<label style='color:red;'>"+m+"</label>");
         

        //return mapping.findForward("ajout");
       return mapping.findForward("calendrierSelect");
    }
}
